from extension import db
from sqlalchemy import Column, String, Boolean, DateTime


# models放置数据库实体类
# class必须继承自db.Model
class Admin(db.Model):
    __tablename__ = 'admin'
    account = db.Column(db.String, primary_key=True)
    password = db.Column(db.String)


class User(db.Model):
    __tablename__ = 'user_login'
    cardID = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String)
    password = db.Column(db.String)
    role = db.Column(db.String)
    money = db.Column(db.Integer)


class Books(db.Model):
    __tablename__ = 'books'
    book_id = db.Column(db.String, primary_key=True)
    isbn = db.Column(db.String)
    name = db.Column(db.String)
    author = db.Column(db.String)
    is_in_library = db.Column(db.Boolean)
    category = db.Column(db.String)
    img = db.Column(db.String)
    borrow_times = db.Column(db.Integer)
    press = db.Column(db.String)
    brief = db.Column(db.String)
    pages = db.Column(db.Integer)


class History(db.Model):
    __tablename__ = 'requests'
    num = db.Column(db.Integer, primary_key=True)
    cardID = db.Column(db.Integer)
    book_name = db.Column(db.String)
    username = db.Column(db.String)
    requestdate = db.Column(db.DateTime)
    status = db.Column(db.String)
    book_id = db.Column(db.String)


class BooksBorrow(db.Model):
    __tablename__ = 'books_borrow'
    book_id = db.Column(db.String, primary_key=True)
    borrower_id = db.Column(db.Integer)
    start_date = db.Column(db.DateTime)
    end_date = db.Column(db.DateTime)
    status = db.Column(db.String)
    book_name = db.Column(db.String)


class Info(db.Model):
    __tablename__ = 'info'
    num = db.Column(db.Integer, primary_key=True)
    send_time = db.Column(db.Date)
    content = db.Column(db.String)
    title = db.Column(db.String)


class Letter(db.Model):
    __table__name = 'letter'
    num = db.Column(db.Integer, primary_key=True)
    content = db.Column(db.String)
    send_time = db.Column(db.DateTime)

#咨询表
class QA(db.Model):
    __table__name = 'qa'
    qa_id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String)
    question = db.Column(db.String)
    answer = db.Column(db.String)